package com.ztjy.statis.controller;

import com.github.pagehelper.PageInfo;
import com.ztjy.bean.City;
import com.ztjy.bean.CustomStatis;
import com.ztjy.bean.FirmStatis;
import com.ztjy.bean.Users;
import com.ztjy.statis.biz.FirmStatisBiz;
import com.ztjy.sys.biz.AreaBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/statis/firm")
public class FirmStatisController {
    @Autowired
    private FirmStatisBiz firmbiz;
    @Autowired
    private AreaBiz abiz;

    @RequestMapping("/allfirmstatis")
    public String findAllFirmStatis(Model model, FirmStatis firmStatis, @RequestParam(defaultValue = "1",value = "pageno")Integer pageNo, HttpSession session){
        Integer pageSize=6;
        Users user=(Users) session.getAttribute("currUser");
        Integer jobId = user.getJobId();
        if (jobId==12||jobId==1){
            PageInfo<FirmStatis> allFirmStatis = firmbiz.findAllFirmStatis(firmStatis, pageNo, pageSize);
            model.addAttribute("firmstatisinfo",allFirmStatis);
            if(firmStatis!=null){
                Integer cityId = firmStatis.getFirmCity();
                City city = abiz.findCityById(cityId);
                firmStatis.setCity(city);
            }
            model.addAttribute("firmStatis",firmStatis);
            return "forward:/statis/purchase/purchaseStatis.html";
        }else{
            return "";
        }
    }

    @RequestMapping("/firmview")
    public String findFirmView(Model model,Integer id,@RequestParam(defaultValue = "1",value = "pageno")Integer pageNo){
        Integer pageSize=6;
        PageInfo<FirmStatis> firmstatisById = firmbiz.findFirmStatisById(id, pageNo, pageSize);
        model.addAttribute("allfirmbyid",firmstatisById);
        model.addAttribute("id",id);
        return "forward:/statis/purchase/purchaseView.html";
    }

    @RequestMapping("/bingzhuang")
    @ResponseBody
    public List<FirmStatis> bingzhuangtu(){
        List<FirmStatis> findbingzhuangtu = firmbiz.findbingzhuangtu();
        return findbingzhuangtu;
    }
}
